package com.godofgamblers.hotelmanagementsystem.service.imp;

import com.godofgamblers.hotelmanagementsystem.dto.OrderMes;
import com.godofgamblers.hotelmanagementsystem.mapper.*;
import com.godofgamblers.hotelmanagementsystem.pojo.*;
import com.godofgamblers.hotelmanagementsystem.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Haonan
 * @date 2019/10/14 - 9:39
 */
@Service
public class ReservationServiceImpl implements ReservationService {
    @Autowired
    private ReservationMapper reservationMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private Order_ItemMapper order_itemMapper;
    @Autowired
    private Room_typeMapper room_typeMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Reservation> findCurrentReservationByUsername(String username) {
        return reservationMapper.findCurrentReservationByUsername(username);
    }

    @Override
    public List<Reservation> findCurrentReservationByPhone(String phone) {
        return reservationMapper.findCurrentReservationByPhone(phone);
    }

    @Override
    public List<Reservation_orderItem> findCurrentReservationItemByOrderId(int orderID) {
        return reservationMapper.findCurrentReservationItemByOrderId(orderID);
    }

    @Override
    public boolean updateCurrentReservationItemFlagByOrderId(String order_item_id) {
        return reservationMapper.updateCurrentReservationItemFlagByOrderId(order_item_id);
    }

    @Override
    public boolean updateCurrentReservationFlagByOrderId(int order_id) {
        return reservationMapper.updateCurrentReservationFlagByOrderId(order_id);
    }

    @Override
    public List<Reservation> findUnreadComment() {
        return reservationMapper.findUnreadComment();
    }

    @Override
    public boolean updateOrderMessageState(int order_id) {
        return reservationMapper.updateOrderMessageState(order_id);
    }

    @Override
    public boolean updateOrderAllMessageState() {
        return reservationMapper.updateOrderAllMessageState();
    }

    @Override
    public Reservation findCurrentReservationByOrderId(int order_id) {
        return reservationMapper.findCurrentReservationByOrderId(order_id);
    }

    @Override
    public OrderMes findReservationItemByOrderItemId(int order_item_id) {

        Order order = new Order();
        Order_item order_item= new Order_item();
        Room_Type room_type = new Room_Type();
        User user = new User();
        //订单编号
        Integer order_id=order_itemMapper.findOrderId(order_item_id);
        //订单信息：状态、编号、总价、订单创建时间、用户id
        order = orderMapper.findOrderinfoByOrderId(order_id);
        order.setOrder_id(order_id);
        //订单项信息：状态、计划入住时间、计划退房时间、房间类型id
        order_item = order_itemMapper.findOrderItemInfoByOrderitemId(order_item_id);
        order_item.setOrder_item_id(order_item_id);
        //房间类型信息
        room_type = room_typeMapper.findRoomTypeInfoByRoomTypeid(order_item.getRoom_type_id());
        room_type.setRoom_type_id(order_item.getRoom_type_id());
        //用户信息
        user = userMapper.findUserinfoByUserId(order.getUser_id());

        OrderMes orderMes = new OrderMes(order_item,order,room_type,user);

        return orderMes;
    }


}
